Add 'splitoutpu' option to text output.
authorrobertl <robertl>
Wed, 18 Jul 2007 17:10:58 +0000 (17:10 +0000)
committerrobertl <robertl>
Wed, 18 Jul 2007 17:10:58 +0000 (17:10 +0000)
text.c
xmldoc/formats/options/text-splitoutput [new file with mode: 0644]

diff --git a/text.c b/text.c
index a8a3a2efa4c4ac4d348cb54f36b11f0837a6aa3f..ab04d7d1b488ca2737cb57d032621dc4f35d0f5c 100644 (file)
--- a/text.c
+++ b/text.c
@@ -32,6 +32,9 @@ static char *txt_encrypt = NULL;
 static char *includelogs = NULL;
 static char *degformat = NULL;
 static char *altunits = NULL;
+static char *split_output = NULL;
+static int waypoint_count;
+static char *output_name;
 
 #define MYNAME "TEXT"
 
@@ -48,6 +51,8 @@ arglist_t text_args[] = {
                "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX },
        { "altunits", &altunits,
                "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX },
+       { "splitoutput", &split_output,
+               "Write each waypoint in a separate file", NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
 
        ARG_TERMINATOR
 };
@@ -57,15 +62,22 @@ arglist_t text_args[] = {
 static void
 wr_init(const char *fname)
 {
-       file_out = gbfopen(fname, "w", MYNAME);
+       waypoint_count = 0;
+       output_name = xstrdup(fname);
+       if (!split_output) {
+               file_out = gbfopen(fname, "w", MYNAME);
+       } 
        mkshort_handle = mkshort_new_handle();
 }
 
 static void
 wr_deinit(void)
 {
-       gbfclose(file_out);
+       if (!split_output) {
+               gbfclose(file_out);
+       }
        mkshort_del_handle(&mkshort_handle);
+       xfree(output_name);
 }
 
 static void
@@ -80,6 +92,14 @@ text_disp(const waypoint *wpt)
        char *tmpout1, *tmpout2;
        char *altout;
        fs_xml *fs_gpx;
+
+       waypoint_count++;
+       
+       if (split_output) {
+               char *thisfname;
+               xasprintf(&thisfname, "%s%d", output_name, waypoint_count);
+               file_out = gbfopen(thisfname, "w", MYNAME);
+       }
        
        lonint = abs((int) wpt->longitude);
        latint = abs((int) wpt->latitude);
@@ -225,14 +245,17 @@ text_disp(const waypoint *wpt)
                gbfprintf(file_out, "\n-----------------------------------------------------------------------------\n");
        else
                gbfprintf(file_out, "\n");
-               
-       
+
+       if (split_output) {
+               gbfclose(file_out);
+               file_out = NULL;
+       }
 }
 
 static void
 data_write(void)
 {
-       if (! suppresssep) 
+       if (! suppresssep && !split_output
                gbfprintf(file_out, "-----------------------------------------------------------------------------\n");
        setshort_length(mkshort_handle, 6);
        waypt_disp_all(text_disp);
diff --git a/xmldoc/formats/options/text-splitoutput b/xmldoc/formats/options/text-splitoutput
new file mode 100644 (file)
index 0000000..fb6b675
--- /dev/null
@@ -0,0 +1,12 @@
+<para>
+  Splits output into separate files for each waypoint by appending a
+  decimal number to the output filename.
+    <example id=split>
+       If "MyPQ.gpx" contains five waypoints, 
+       <userinput>
+           gpsbabel -i gpx -f MyPocketQuery -o text,split -F blah
+       </userinput>
+       will result in files named blah1 ... blah5, each containing info
+       from one of those waypoints.
+    </example>
+</para>